package com.nhim.cms.admin.client;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;
import com.nhim.cms.admin.client.eldf.ui.ElementDefinition;
import com.nhim.cms.admin.client.eldf.ui.ElementDefinitionList;
import com.nhim.cms.admin.client.ctype.ui.ContentType;
import com.nhim.cms.admin.client.customwidget.ui.CustomWidgetList;
import com.nhim.cms.admin.client.place.CustomWidgetListPlace;
import com.nhim.cms.admin.client.place.DashboardPlace;
import com.nhim.cms.admin.client.place.ElementDefinitionListPlace;
import com.nhim.cms.admin.client.place.ElementDefinitionPlace;
import com.nhim.cms.admin.client.place.ContentTypePlace;

public class NhimCMSAdminActivityMapper implements ActivityMapper {

	private final Dashboards dashboard;
	private final ElementDefinitionList elementDefinitionList;
	private final ElementDefinition elementDefinition;
	private final CustomWidgetList customWidgetList;
	// 2011/3/26 HUNG ADD START
	private final ContentType contentType;
	// 2011/3/26 HUNG ADD END

	public NhimCMSAdminActivityMapper(Dashboards dashboard
			,ElementDefinitionList elementDefinitionList
			,ElementDefinition elementDefinition
			,ContentType contentType, CustomWidgetList customWidgetList) {
		this.dashboard = dashboard;
		this.elementDefinitionList = elementDefinitionList;
		this.elementDefinition = elementDefinition;
		this.customWidgetList = customWidgetList;
		// 2011/3/26 HUNG ADD START
		this.contentType = contentType;
		// 2011/3/26 HUNG ADD END
	}

	public Activity getActivity(Place place) {
		if (place instanceof DashboardPlace) {
			return dashboard;
		}
		if (place instanceof ElementDefinitionListPlace) {
			elementDefinitionList
					.updateForPlace((ElementDefinitionListPlace) place);
			return elementDefinitionList;
		}
		if (place instanceof ElementDefinitionPlace) {
			elementDefinition.updateForPlace((ElementDefinitionPlace) place);
		      return elementDefinition;
		}
		if(place instanceof CustomWidgetListPlace){
			customWidgetList.updateForPlace((CustomWidgetListPlace)place);
			return customWidgetList;
		}
		// 2011/3/26 HUNG ADD START
		if (place instanceof ContentTypePlace) {
			contentType.updateForPlace((ContentTypePlace) place);
		      return contentType;
		}
		// 2011/3/26 HUNG ADD END

		return null;
	}

}
